package com.iflysse.controller;


import com.iflysse.common.ActivityState;
import com.iflysse.pojo.bo.CommonBoResp;
import com.iflysse.pojo.bo.req.TestBoReq;
import com.iflysse.pojo.vo.common.CommonVoResp;
import com.iflysse.pojo.vo.req.ActivityIdVoReq;
import com.iflysse.pojo.vo.req.ActivityStateVoReq;
import com.iflysse.pojo.vo.req.AddTestVoReq;
import com.iflysse.pojo.vo.req.TeachingClassIdVoReq;
import com.iflysse.pojo.vo.resp.ClassActivityVoResp;
import com.iflysse.pojo.vo.resp.StudentTaskDetailAnalyseVoResp;
import com.iflysse.pojo.vo.resp.StudentTestDetailAnalyseVoResp;
import com.iflysse.services.IActivityService;
import com.iflysse.utils.CommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("/classActivity")
@Api(value = "老师端教学活动")
public class ClassActivityController{

    @Autowired
    IActivityService activityService;

    /**
     * 教师端获取学生学习任务详情
     */
    @PostMapping("/queryStudentTaskDetail")
    @ApiOperation("教师端获取学生任务学习详情")
    public StudentTaskDetailAnalyseVoResp queryStudentTaskDetail(ActivityIdVoReq activityIdVoReq){
        StudentTaskDetailAnalyseVoResp studentTaskDetailAnalyseVoResp=new StudentTaskDetailAnalyseVoResp();
        return studentTaskDetailAnalyseVoResp;

    }




    /**
     * 教师端获取学生测试详情
     */
    @PostMapping("/queryStudentTestDetail")
    @ApiOperation("教师端获取学生测试详情")
    public StudentTestDetailAnalyseVoResp queryStudentTestDetail(ActivityIdVoReq activityIdVoReq){

        StudentTestDetailAnalyseVoResp studentTestDetailAnalyseVoResp=new StudentTestDetailAnalyseVoResp();
        return studentTestDetailAnalyseVoResp;

    }







    /**
     * 老师端 查询教学班级内得教学活动列表
     *
     */
    @PostMapping("/loadActivityByTeacherClassId")
    @ApiOperation("老师端查询教学班级内得教学活动列表")
    public ClassActivityVoResp doLoadActivityByTeacherClassId(TeachingClassIdVoReq teachingClassIdVoReq){
        ClassActivityVoResp classActivityVoResp=new ClassActivityVoResp();
        return  classActivityVoResp;
    }


    /**
     * 老师端 发布测试
     */
    @PostMapping("/addTest")
    @ApiOperation("老师端发布测试")
    public CommonVoResp doAddTest(AddTestVoReq addTestVoReq){

        CommonVoResp commonVoResp=new CommonVoResp();
        try{
            TestBoReq testBoReq = CommonUtil.objToObj(addTestVoReq,TestBoReq.class);
            //testBoReq.setExpirationDate(CommonUtil.stringSourceToDate(addTestVoReq.getExpirationDate(),CommonUtil.pattern));
            testBoReq.setExpirationDate(CommonUtil.stringSourceToDate(addTestVoReq.getExpirationDate(),CommonUtil.pattern));

            List<String> questionIdList = new ArrayList<>();
            String questionIds = addTestVoReq.getQuestionIdList();
            String[] questions = questionIds.split(",");

            // 方法一
            for(String s : questions){
                questionIdList.add(s);
            }

            // 方法二
            //questionIdList = Arrays.asList(questions);
            // 添加问题列表
            testBoReq.setQuestionIdList(questionIdList);

            // 转换状态
            if(addTestVoReq.getState().equals(ActivityState.STATE_NO_PUBLISH.getStateId())){
                testBoReq.setState(ActivityState.STATE_NO_PUBLISH);
            }else if(addTestVoReq.getState().equals(ActivityState.STATE_RUNNING.getStateId())){
                testBoReq.setState(ActivityState.STATE_RUNNING);
            }else if(addTestVoReq.getState().equals(ActivityState.STATE_FINISH.getStateId())){
                testBoReq.setState(ActivityState.STATE_FINISH);
            }

            CommonBoResp commonBoResp = activityService.save(testBoReq);
            CommonUtil.printBoResultToVoResult(commonBoResp,commonVoResp);
        }catch (Exception e){
            e.printStackTrace();
        }

        return commonVoResp;
    }


    /**
     * 老师端教学班级中 删除活动
     */
    @PostMapping("/deleteActivity")
    @ApiOperation("老师端教学班级中删除活动")
    public CommonVoResp doDeleteActivity(ActivityIdVoReq activityIdVoReq){
        CommonVoResp commonVoResp=new CommonVoResp();
        return commonVoResp;
    }


    /**
     * 教师端 教学活动 更新活动状态,包括暂存后点击发布功能
     */
    @PostMapping("/updateActivityState")
    @ApiOperation("教师端教学活动更新活动状态,包括暂存后点击发布功能")
    public CommonVoResp doUpdateActivityState(ActivityStateVoReq activityStateVoReq) {

        CommonVoResp commonVoResp = new CommonVoResp();
        return commonVoResp;
    }
}
